var app = getApp();
var WxParse  = app.WxParse;
// var WxParse = require('../../wxParse/wxParse.js');
var count = 0;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    article: {},
    wxParseData: {},
    sysinfo:{},
    id: 0,
    tcolor: '',
    type:'',
    isshow: 0,
    stars: [0, 1, 2, 3, 4],
    normalSrc: '../../resource/images/no-star.png',
    selectedSrc: '../../resource/images/full-star.png',
    halfSrc: '../../resource/images/half-star.png',
    key: 5,//评分
    content: '',
    oid: '',
    commentList: {},
    voteArr: [],
    showVoteHoverImg: 0,
    cateSys: {},
    showModalStatus: false,
    isShow: false,
    code: '',
    show_share: 0,
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
 
//   onShow:function(options){
//     swan.setNavigationBarColor({
//       frontColor: '#ffffff',
//       backgroundColor: '#ff0000',
//     })
//   },
  onLoad: function (options) {


    var sysinfo = swan.getStorageSync('info');
        app.head_backgroup(sysinfo);
        this.setData({
        sysinfo: sysinfo 
        })
    var id = options.id;
    var type = options.type;
    var that = this;
    var uniacid = app.siteInfo.uniacid;
    this.setData({
      id: id,
      type:type
    });




    //如果已经点赞过了，那么让点赞图片换成hover图标
    var voteArr = new Array();
    voteArr = swan.getStorageSync('voteArr');
    if (voteArr) {
      if (voteArr.indexOf(id) != -1) {
        this.setData({
          showVoteHoverImg: 1
        })
      }
    }

    if(type == 'news'){

        var post_url = app.util.url('entry/baiduapp/NewsContent');
            app.globalSeo('news_details','',id).then(res =>{
                // console.log(res);
                swan.setPageInfo({

                        title: res.seo_title,
                        keywords: res.seo_keywords,
                        description: res.seo_description,
                        articleTitle: res.seo_articleTitle,
                        image:  res.seo_img,
                        releaseDate: res.seo_time,
                    })

            })



    }else if(type = 'product'){
         var post_url = app.util.url('entry/baiduapp/ProductContent');

             app.globalSeo('product_details','',id).then(res =>{
                // console.log(res);
                swan.setPageInfo({

                        title: res.seo_title,
                        keywords: res.seo_keywords,
                        description: res.seo_description,
                        articleTitle: res.seo_articleTitle,
                        image:  res.seo_img,
                        releaseDate: res.seo_time,
                    })

            })


    }else{
        var post_url = app.util.url('entry/baiduapp/NewsContent');
    }

    swan.request({
      url: post_url,
      method: 'GET',
      dataType: 'json',
      data: {
        uniacid: app.siteInfo.uniacid,
        m: app.siteInfo.mName,
        id: id,
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        WxParse.wxParse('wxParseData', 'html', res.data.data.message, that, 10);
        that.setData({
          article: res.data.data,
          show_share: res.data.data.show_share,
        });
        
        swan.setNavigationBarTitle({
          title: res.data.data.title,
        })
      }
    });




  },
 
  closeRoom: function () {
    this.setData({
      isShow: false
    })
  },

  notice: function (str) {
    swan.showModal({
      title: str,
      content: '',
      success: function (res) {

      }
    })
  },
  onShareAppMessage: function (res) {
    var list = this.data.article;
    // console.log(this.data.article);
    var title, path,path_h;
    if(this.data.type == 'news'){
        path_h = '/pages/content/content?type=news&id=' + this.data.id
    }else{
        path_h =  '/pages/content/content?type=product&id=' + this.data.id
    }
    // console.log(path_h);

    if (list.diyshare == '1') {
      return {
        title: list.sharetitle,
        imageUrl: list.shareimg,
        path: $path_h
      }
    } else {

      return {
        title: this.data.article.title,
        path: path_h
      }
    }

  },


  textareaBlur: function (e) {
    this.setData({
      content: e.detail.value
    })
  },




})